# 1、hook cookie set 方法
# (function(){
#     Object.defineProperty(document, 'cookie', {
#         set:function(val){
#             debugger
#             return val
#         }
#     })
# })();

import requests
import execjs

url = "https://www.python-spider.com/api/challenge3"

headers = {}
cookies = {}


def getCookieParams():
    with open('./js.js', 'r', encoding='utf-8') as f:
        js_code = f.read()
    js_comp = execjs.compile(js_code)
    return js_comp.call("get_m")


answer = 0
for i in range(1, 101):
    list = {
        "page": i
    }
    # 获取解密header
    cookies["m"] = getCookieParams()
    r = requests.post(url, headers=headers,cookies=cookies, data=list)
    data = r.json()['data']
    print(data)
    for item in data:
        answer += int(item['value'])

print(answer)
